//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================



using System;
using System.Collections.Generic;
using System.Text;
using LitwareHR.Portfolio.Gateways;
using Shp.Runtime.Contract;

namespace LitwareHR.PrivateApp.Presenters.ConfigCusto
{
    public class EditViewPresenter
    {
        private IEditViewView _view;

        public EditViewPresenter(IEditViewView view)
        {
            _view = view;
        }

        private EditViewPresenter()
        {
        }

        public void OnViewLoaded(string tenantAlias, string entityDefName, Guid viewDefId)
        {
            EntityField[] entityFields = DatamodelGateway.GetEntityDefFields(tenantAlias, entityDefName);
            _view.ShowEntityFields(entityFields);
            StringPair[] viewFields = DatamodelGateway.GetViewDefFieldsById(tenantAlias, viewDefId);
            _view.ShowViewFields(viewFields);
        }

        public void OnAdd(string labelName, string fieldName, StringPair[] viewFields)
        {
            List<StringPair> tmp = new List<StringPair>(viewFields);
            tmp.Add(new StringPair(labelName, fieldName));
            _view.ShowViewFields(tmp.ToArray());
        }

        public void OnRemove(string key, StringPair[] viewFields)
        {
            viewFields = StringPair.Remove(key, viewFields);
            _view.ShowViewFields(viewFields);
        }

        public void OnSave(Guid viewDefId, StringPair[] viewFields)
        {
            DatamodelGateway.UpdateViewDef(viewDefId, viewFields);
        }
    }
}
